package mutsumimod.powers;

import basemod.ReflectionHacks;
import com.evacipated.cardcrawl.modthespire.lib.*;
import com.evacipated.cardcrawl.modthespire.patcher.PatchingException;
import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.animations.VFXAction;
import com.megacrit.cardcrawl.actions.common.ApplyPowerAction;
import com.megacrit.cardcrawl.cards.DamageInfo;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.AbstractCreature;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import com.megacrit.cardcrawl.powers.AbstractPower;
import javassist.CannotCompileException;
import javassist.CtBehavior;
import mutsumimod.MutsumiMod;
import mutsumimod.vfx.WhiteMoonEffect;

import java.util.ArrayList;

public class WhiteMoonPower extends BasePower {
    public static final String POWER_ID = MutsumiMod.makeID(WhiteMoonPower.class.getSimpleName());
    private boolean triggered=false;
    private WhiteMoonEffect effect=new WhiteMoonEffect(AbstractDungeon.player);

    public WhiteMoonPower(AbstractCreature owner) {
        super(POWER_ID, PowerType.BUFF, false, owner, 0);
    }

    //本身的loseHP钩子不能判断info的类型
    @Override
    public void betterOnLoseHp(DamageInfo info, int damageAmount) {
        if(info.type.equals(DamageInfo.DamageType.NORMAL)&&damageAmount > 0){
            flash();
            triggered=true;
        }
    }

    @Override
    public void atEndOfTurn(boolean isPlayer) {
        if(isPlayer){
            addToTop(new VFXAction(effect));
        }
    }

    @Override
    public void atStartOfTurn() {
        removePower();
        effect.close();
    }

    @Override
    public void updateDescription() {
        if(!triggered){
            description = DESCRIPTIONS[0] + DESCRIPTIONS[1];
        }else{
            description = DESCRIPTIONS[0] + DESCRIPTIONS[2];
        }
    }

    @Override
    public int onAttackedToChangeDamage(DamageInfo info, int damageAmount){
        if(damageAmount>0&&triggered&&info.type.equals(DamageInfo.DamageType.NORMAL)){
            return 0;
        }
        return damageAmount;
    }
}
